package service

import (
	"Graphite/database"
	"Graphite/model"
	"Graphite/util"
	"context"
	"encoding/json"
	"fmt"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"go.mongodb.org/mongo-driver/mongo/options"
	"log"
	"strconv"
	"strings"

	//"strconv"
	//"strings"
)

//配置表
func GetConfig(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64          `json:"total_count"` //数据条数
		Results     []model.PeiZhi `json:"results"`     //定义model数组接收转换json后数据
	}
	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)

	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}

	return data
}

//得到质量要求数据

func GetQuality(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64                   `json:"total_count"` //数据条数
		Results     []model.QualityRequired `json:"results"`     //定义model数组接收转换json后数据
	}
	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)

	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}

	return data
}

//得到装炉报告

func GetLoad(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage2(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64            `json:"total_count"` //数据条数
		Results     []model.LoadOven `json:"results"`     //定义model数组接收转换json后数据
	}
	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount2(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//得到送电曲线

func GetElec(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage2(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64                    `json:"total_count"` //数据条数
		Results     []model.ElectricityCurve `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)

	data.Total_count = util.GetCount2(col, key)
	fmt.Printf("结果:%d", data.Total_count)

	if err != nil {
		log.Println(err)
	}
	return data
}

//得到基本信息

func GetBasicInfo(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage2(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64                    `json:"total_count"` //数据条数
		Results     []model.BasicInformation `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount2(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//得到详细信息

func GetDetailedInfo(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage2(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64                       `json:"total_count"` //数据条数
		Results     []model.DetailedInformation `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount2(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//得到产品信息

func GetProductInfo(key string, col string, page int64, per_page int64) interface{} {
	db := database.GetMongoDB()
	Collection := db.Collection(col)
	var findoptions *options.FindOptions
	if per_page > 0 {
		findoptions = &options.FindOptions{}
		findoptions.SetLimit(per_page)             //每页数据数量
		findoptions.SetSkip(per_page * (page - 1)) //根据第几页跳过数据
	}
	cur, err := Collection.Find(context.Background(), bson.M{"task": primitive.Regex{Pattern: key}}, findoptions)
	if err != nil {
		log.Println(err)
	}
	if err := cur.Err(); err != nil {
		log.Println(err)
	}
	var all []bson.M
	err = cur.All(context.Background(), &all)
	if err != nil {
		log.Println(err)
	}
_:
	cur.Close(context.Background())
	fmt.Println("-----------")
	jsonStr, err := json.Marshal(all)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64              `json:"total_count"` //数据条数
		Results     []model.Production `json:"results"`     //定义model数组接收转换json后数据
	}
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetProCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//浸渍小时数据

func GetHourInfo(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64                   `json:"total_count"` //数据条数
		Results     []model.DippingHourData `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)

	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//天然气用量

func GetGasInfo(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64                   `json:"total_count"` //数据条数
		Results     []model.NaturalGasUsage `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//浸渍系统运行记录

func GetSysNoteInfo(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64                     `json:"total_count"` //数据条数
		Results     []model.DippingSystemNote `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//成型
//筛分记录
func GetScrInfo(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64                   `json:"total_count"` //数据条数
		Results     []model.ScreeningRecord `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//配料记录
func GetIngredInfo(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64                    `json:"total_count"` //数据条数
		Results     []model.IngredientRecord `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//质检
//检查日报
func GetDaily(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64               `json:"total_count"` //数据条数
		Results     []model.DailyReport `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//隧道窑
//测点信息
func GetLocInfo(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64                `json:"total_count"` //数据条数
		Results     []model.LocationInfo `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//进车信息
func GetIncarInfo(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64              `json:"total_count"` //数据条数
		Results     []model.Incar_Info `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//出车信息
func GetOutcarInfo(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64               `json:"total_count"` //数据条数
		Results     []model.Outcar_Info `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//交接班
func GetHan_SucInfo(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64                      `json:"total_count"` //数据条数
		Results     []model.Handover_Successor `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//库管
//原始记录
func GetInitInfo(key string, col string, page int64, per_page int64) interface{} {
	res := util.GetMessage(key, col, page, per_page)
	jsonStr, err := json.Marshal(res)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64              `json:"total_count"` //数据条数
		Results     []model.InitRecord `json:"results"`     //定义model数组接收转换json后数据
	}

	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = util.GetCount(col, key)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}



/*货物管理
数量表
 */
func GetAmount(dia string,time_stamp1 string,time_stamp2 string,page int64, per_page int64,col string) interface{}{
	db := database.GetMongoDB()
	Collection := db.Collection(col)
	var findoptions *options.FindOptions
	if per_page > 0 {
		findoptions = &options.FindOptions{}
		findoptions.SetLimit(per_page)             //每页数据数量
		findoptions.SetSkip(per_page * (page - 1)) //根据第几页跳过数据
	}
	//
	cur, err := Collection.Find(context.Background(), bson.M{"time_stamp":bson.M{"$gte":time_stamp1,"$lte":time_stamp2},"diameter":dia}, findoptions) //搜索空字符串得到全部数据
	if err != nil {
		log.Println(err)
	}
	if err := cur.Err(); err != nil {
		log.Println(err)
	}
	var all []bson.M
	err = cur.All(context.Background(), &all)
	if err != nil {
		log.Println(err)
	}

  	_:cur.Close(context.Background())
	fmt.Println("-----------")
	jsonStr, err := json.Marshal(all)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64              `json:"total_count"` //数据条数
		Results     []model.Amount `json:"results"`     //定义model数组接收转换json后数据
	}
	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = GetCou2(dia,time_stamp1,time_stamp2,col)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

func GetCou(time_stamp1 string,time_stamp2 string,col string) int64 {
	db := database.GetMongoDB()
	collection := db.Collection(col)
	total_count, err := collection.CountDocuments(context.Background(), bson.M{"time_stamp":bson.M{"$gte":time_stamp1,"$lte":time_stamp2}})
	if err != nil {
		log.Println(err)
	}
	return total_count
}
func GetCou2(dia string,time_stamp1 string,time_stamp2 string,col string) int64 {
	db := database.GetMongoDB()
	collection := db.Collection(col)
	total_count, err := collection.CountDocuments(context.Background(), bson.M{"time_stamp":bson.M{"$gte":time_stamp1,"$lte":time_stamp2},"diameter":dia})
	if err != nil {
		log.Println(err)
	}
	return total_count
}
func GetWeight(dia string,time_stamp1 string,time_stamp2 string,page int64, per_page int64,col string) interface{}{
	db := database.GetMongoDB()
	Collection := db.Collection(col)
	var findoptions *options.FindOptions
	if per_page > 0 {
		findoptions = &options.FindOptions{}
		findoptions.SetLimit(per_page)             //每页数据数量
		findoptions.SetSkip(per_page * (page - 1)) //根据第几页跳过数据
	}
	//"$lt":time_stamp2
	cur, err := Collection.Find(context.Background(), bson.M{"time_stamp":bson.M{"$gte":time_stamp1,"$lte":time_stamp2},"diameter":dia}, findoptions) //搜索空字符串得到全部数据
	if err != nil {
		log.Println(err)
	}
	if err := cur.Err(); err != nil {
		log.Println(err)
	}
	var all []bson.M
	err = cur.All(context.Background(), &all)
	if err != nil {
		log.Println(err)
	}

_:cur.Close(context.Background())
	fmt.Println("-----------")
	jsonStr, err := json.Marshal(all)
	if err != nil {
		log.Println(err)
	}
	var data struct {
		Total_count int64              `json:"total_count"` //数据条数
		Results     []model.Weight `json:"results"`     //定义model数组接收转换json后数据
	}
	//fmt.Printf("结果:%v",string(jsonStr))
	err = json.Unmarshal([]byte(jsonStr), &data.Results)
	fmt.Printf("结果:%v", data.Results)
	data.Total_count = GetCou2(dia,time_stamp1,time_stamp2,col)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
		log.Println(err)
	}
	return data
}

//按照时间查找货物汇总表

func GetCargoSummary(time_stamp1 string,time_stamp2 string,page int64, per_page int64,col string) interface{} {
	db := database.GetMongoDB()
	Weight :=db.Collection("weight")
	cur, err := Weight.Find(context.Background(), bson.M{"time_stamp":bson.M{"$gte":time_stamp1,"$lte":time_stamp2}}) //搜索空字符串得到全部数据
	if err != nil {
		log.Println(err)
	}
	if err := cur.Err(); err != nil {
		log.Println(err)
	}
	var all []bson.M
	err = cur.All(context.Background(), &all)
	if err != nil {
		log.Println(err)
	}
	_:cur.Close(context.Background())
	jsonStr, err := json.Marshal(all)
	if err != nil {
		log.Println(err)
	}
	var weight []model.Weight
	err = json.Unmarshal( []byte (jsonStr), &weight)
	weight_length := len(weight)

	var tmps []string
	var cargo model.CargoSummary
	var cargos  []model.CargoSummary
	cargos_length := len(cargos)

	for i := 0; i < weight_length; i++ {
		if weight[i].Diameter=="次品" {
			continue
		}
		parts := strings.SplitN(weight[i].Diameter, "Φ", 2)
		diameter, err := strconv.ParseInt(parts[1], 10, 64)
		if err!=nil {
			log.Println(err)
		}
		if diameter >= 400 || diameter == 250 {
			parts := strings.SplitN(weight[i].Process_Length, "-", 2)
			var tmp = weight[i].Diameter + parts[0]

			if util.In(tmp,tmps) {
				for j:=0 ; j < cargos_length && cargos != nil; j++ {
					if cargos[j].Process_Specifications == tmp {
						t1,_ := strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Finish_Product ), 64)
						t2,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].RoughCast ), 64)
						t3,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Second_Burn + weight[i].Graphitization_Furnace ), 64)
						t4,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Once_Dip ), 64)
						t5,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Once_Burn), 64)
						t6,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f", weight[i].Once_Burn_Furnace + weight[i].Green_Body), 64)
						cargos[j].Finish_Product = cargos[j].Finish_Product + t1
						cargos[j].RoughCast = cargos[j].RoughCast + t2
						cargos[j].Second_Burn = cargos[j].Second_Burn + t3
						cargos[j].Once_Dip = cargos[j].Once_Dip + t4
						cargos[j].Once_Burn = cargos[j].Once_Burn + t5
						cargos[j].Green_Body = cargos[j].Green_Body + t6
						cargos[j].Diameter = weight[i].Diameter
						break
					}
				}
			} else {
				t1,_ := strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Finish_Product ), 64)
				t2,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].RoughCast ), 64)
				t3,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Second_Burn + weight[i].Graphitization_Furnace ), 64)
				t4,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Once_Dip ), 64)
				t5,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Once_Burn), 64)
				t6,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f", weight[i].Once_Burn_Furnace + weight[i].Green_Body), 64)
				cargo.Finish_Product =  t1
				cargo.RoughCast =  t2
				cargo.Second_Burn =  t3
				cargo.Once_Dip =  t4
				cargo.Once_Burn = t5
				cargo.Green_Body =  t6
				cargo.Diameter = weight[i].Diameter
				cargo.Process_Specifications = tmp
				tmps = append(tmps, tmp)
				cargos = append(cargos, cargo)
				cargos_length = len(cargos)
			}

		} else {
			switch diameter {
			case 350,300,200:
				{
					var  tmp string
					if weight[i].Process_Length == "RP"{
						tmp = weight[i].Diameter + "RP"
					}else {
						parts := strings.SplitN(weight[i].Process_Length, "-", 2)
						tmp = weight[i].Diameter + parts[0]
					}
					if util.In(tmp,tmps) {
						for j:=0 ; j < cargos_length && cargos != nil; j++ {
							if cargos[j].Process_Specifications == tmp {
								t1,_ := strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Finish_Product ), 64)
								t2,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].RoughCast ), 64)
								t3,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Second_Burn + weight[i].Graphitization_Furnace ), 64)
								t4,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Once_Dip ), 64)
								t5,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Once_Burn), 64)
								t6,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f", weight[i].Once_Burn_Furnace + weight[i].Green_Body), 64)
								cargos[j].Finish_Product = cargos[j].Finish_Product + t1
								cargos[j].RoughCast = cargos[j].RoughCast + t2
								cargos[j].Second_Burn = cargos[j].Second_Burn + t3
								cargos[j].Once_Dip = cargos[j].Once_Dip + t4
								cargos[j].Once_Burn = cargos[j].Once_Burn + t5
								cargos[j].Green_Body = cargos[j].Green_Body + t6
								cargos[j].Diameter = weight[i].Diameter
								break
							}
						}
					} else {
						t1,_ := strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Finish_Product ), 64)
						t2,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].RoughCast ), 64)
						t3,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Second_Burn + weight[i].Graphitization_Furnace ), 64)
						t4,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Once_Dip ), 64)
						t5,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Once_Burn), 64)
						t6,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f", weight[i].Once_Burn_Furnace + weight[i].Green_Body), 64)
						cargo.Finish_Product =  t1
						cargo.RoughCast =  t2
						cargo.Second_Burn =  t3
						cargo.Once_Dip =  t4
						cargo.Once_Burn = t5
						cargo.Green_Body =  t6
						cargo.Diameter = weight[i].Diameter
						cargo.Process_Specifications = tmp
						tmps = append(tmps, tmp)
						cargos = append(cargos, cargo)
						cargos_length = len(cargos)
					}
				}
			default:
				{
					parts := strings.SplitN(weight[i].Process_Length, "(", 2)
					var tmp = weight[i].Diameter + parts[0]
					if util.In(tmp,tmps) {
						for j:=0 ; j < cargos_length && cargos != nil; j++ {
							if cargos[j].Process_Specifications == tmp {
								t1,_ := strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Finish_Product ), 64)
								t2,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].RoughCast ), 64)
								t3,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Third_Burn+weight[i].Forth_Burn ), 64)
								t4,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Once_Dip ), 64)
								t5,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Once_Burn), 64)
								t6,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f", weight[i].Once_Burn_Furnace + weight[i].Green_Body), 64)
								cargos[j].Finish_Product = cargos[j].Finish_Product + t1
								cargos[j].RoughCast = cargos[j].RoughCast + t2
								cargos[j].Second_Burn = cargos[j].Second_Burn + t3
								cargos[j].Once_Dip = cargos[j].Once_Dip + t4
								cargos[j].Once_Burn = cargos[j].Once_Burn + t5
								cargos[j].Green_Body = cargos[j].Green_Body + t6
								cargos[j].Diameter = weight[i].Diameter
								break
							}
						}
					} else {
						t1,_ := strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Finish_Product ), 64)
						t2,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].RoughCast ), 64)
						t3,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Third_Burn+weight[i].Forth_Burn ), 64)
						t4,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Once_Dip ), 64)
						t5,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f",weight[i].Once_Burn), 64)
						t6,_ :=strconv.ParseFloat(fmt.Sprintf("%.1f", weight[i].Once_Burn_Furnace + weight[i].Green_Body), 64)
						cargo.Finish_Product =  t1
						cargo.RoughCast =  t2
						cargo.Second_Burn =  t3
						cargo.Once_Dip =  t4
						cargo.Once_Burn = t5
						cargo.Green_Body =  t6
						cargo.Diameter = weight[i].Diameter
						cargo.Process_Specifications = tmp
						tmps = append(tmps, tmp)
						cargos = append(cargos, cargo)
						cargos_length = len(cargos)
					}
				}
			}
		}
	}

	var data struct {
	Total_count int64              `json:"total_count"` //数据条数
	Result1     []model.CargoSummary `json:"result1"`     //定义model数组接收转换json后数据
	Result2		[]model.CargoSummary	`json:"result2"`
	}

	for i := 0; i < cargos_length && cargos!= nil ; i++ {
		parts := strings.SplitN(cargos[i].Diameter, "Φ", 2)
		j, err := strconv.ParseInt(parts[1], 10, 64)
		if err!=nil {
			log.Println(err)
		}
		if j%50==0 {
			data.Result1 = append(data.Result1, cargos[i])
		} else {
			data.Result2 = append(data.Result2, cargos[i])
		}
	}

	data.Total_count = int64(cargos_length)
	fmt.Printf("结果:%d", data.Total_count)
	if err != nil {
	log.Println(err)
	}
	return data
}
